/* 
 * GuiExceptionHandler.java 08.10.2011
 *  
 *  
 * Candidate: Alessandra Otterbach
 * Prometric ID: Algisina1
 * Username: Algisina
 *  
 * Sun Certified Developer for Java 2 Platform, Standard Edition Programming 
 * Assignment (CX-310-252A)
 *  
 * This class is part of the Programming Assignment of the Sun Certified 
 * Developer for Java 2 Platform, Standard Edition certification program, must 
 * not be used out of this context and must be used exclusively by Sun 
 * Microsystems, Inc. 
 */  
package suncertify.ps;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
 * Handles Gui Exception by showing it to the user.
 * 
 * @author Alessandra Otterbach
 *
 */
public class GuiExceptionHandler {
    
    /**
     * Displays error message to user in separate window.
     *
     * @param msg The message displayed in the error window.
     */
    public static void handleGuiException(String message) {
        JOptionPane error = new JOptionPane(message,
                                            JOptionPane.ERROR_MESSAGE,
                                            JOptionPane.DEFAULT_OPTION);
        JDialog dialog = error.createDialog(null, "ERROR");

        // Center on screen
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((d.getWidth() - dialog.getWidth()) / 2);
        int y = (int) ((d.getHeight() - dialog.getHeight()) / 2);
        dialog.setLocation(x, y);

        dialog.setVisible(true);
    }

}
